# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
        head = ListNode(0)
        now = head

        now.val = (l1.val + l2.val) % 10
        temp = int((l1.val + l2.val) / 10)

        while(l1.next or l2.next or temp):
            val1 ,val2 = 0,0
            if l1.next:
                l1 = l1.next
                val1 = l1.val
            
            if l2.next:
                l2 = l2.next
                val2 = l2.val

            now.next = ListNode(0)
            now.next.val = (val1 + val2 + temp) % 10
            temp = int((val1 + val2 + temp) / 10)
            now = now.next

        return head